from collections import deque
direct = [[-1,0],[0, 1], [1, 0], [0, -1]]
first = set()
second = set()

def bfs(grid, visited, x, y, fs):
    queue = deque()
    queue.append([x,y])
    
    while queue:
        cur_x,cur_y= queue.popleft()
    
        if visited[cur_y][cur_x]:
            continue
    
        visited[cur_y][cur_x] = True
        fs.add((cur_y, cur_x))
        
        for i, j in direct:
            next_x = cur_x + i
            next_y = cur_y + j
            if (
                0<= next_x < len(grid[0]) 
                and 0<=next_y<len(grid) 
                and grid[next_y][next_x]>=grid[cur_y][cur_x]
                ):
                queue.append([next_x, next_y])

def main():
    N,M = map(int, input().split())
    
    grid = []
    for i in range(N):
        grid.append(list(map(int, input().split())))
    
    
    global first, second
    
    visited = [[False]*M for i in range(N)]
    for i in range(N):
        bfs(grid, visited, 0, i, first)
    for i in range(M):
        bfs(grid, visited, i, 0, first)
        
    visited = [[False]*M for i in range(N)]
    for i in range(N):
        bfs(grid, visited, M-1, i, second)
    for i in range(M):
        bfs(grid, visited, i, N-1, second)
    
    res = first & second
    for i, j in res:
        print(f"{i} {j}")
    
main()
